﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Runtime.InteropServices;

namespace Brain.Editor
{
    public static class TrackBarUtil
    {
        public static Rectangle GetSlider(IntPtr handle)
        {
            RECT rc = new RECT();
            SendMessageRect(handle, TBM_GETTHUMBRECT, IntPtr.Zero, ref rc);
            return new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
        }
        public static Rectangle GetChannel(IntPtr handle)
        {
            RECT rc = new RECT();
            SendMessageRect(handle, TBM_GETCHANNELRECT, IntPtr.Zero, ref rc);
            return new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
        }
        private static readonly int TBM_GETCHANNELRECT = 0x400 + 26;
        private static readonly int TBM_GETTHUMBRECT = 0x400 + 25;
        private struct RECT { public int left, top, right, bottom; }

        [DllImport("user32.dll", EntryPoint = "SendMessageW")]
        private static extern IntPtr SendMessageRect(IntPtr hWnd, int msg, IntPtr wp, ref RECT lp);
    }
}
